package com.xianyun.site.iblog.user.executor.handle;

import com.xianyun.site.iblog.common.core.exception.LoginTypeErrorException;
import com.xianyun.site.iblog.common.core.utils.SpringBeanUtil;
import com.xianyun.site.iblog.dto.user.SystemUserLoginQry;
import com.xianyun.site.iblog.dto.user.data.SystemUserDTO;
import com.xianyun.site.iblog.user.executor.handle.config.HandleCheck;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * 登录状态
 * @author mac_zyj
 */
@Component
public class LoginCheckContext {

    private BaseLoginCheckHandle currentHandle;

    public LoginCheckContext() {

    }

    public LoginCheckContext(int loginType) {
        setCurrentHandle(loginType);
    }

    public void setCurrentHandle(Integer loginType){
        Assert.notNull(loginType,"请确认登录类型是否正确");
        currentHandle= SpringBeanUtil.getBean(HandleCheck.getLoginHandleByType(loginType));
    }

    public SystemUserDTO loginUser(SystemUserLoginQry systemUserLoginQry){
        if (null != currentHandle){
            return currentHandle.loginExecute(systemUserLoginQry);
        }
        throw new LoginTypeErrorException("请确认登录类型是否正确!");
    }

}
